// 多语言配置文件
const i18nData = {
    zh: {
        // 通用界面文本
        ui: {
            gameTitle: "校园惊魂",
            selectLanguage: "选择语言 / Choose Language / 言語を選択",
            chinese: "中文",
            english: "English",
            japanese: "日本語",
            startGame: "开始游戏",
            about: "关于",
            returnToMain: "返回主界面",
            selectChapter: "选择章节",
            playerName: "你的名字:",
            nameplaceholder: "输入你的名字...",
            selectGender: "选择性别:",
            male: "男",
            female: "女",
            // 性别显示翻译
            genderDisplay: {
                male: "男",
                female: "女",
                "沃尔玛购物袋": "沃尔玛购物袋",
                "武装直升机": "武装直升机"
            },
            backpack: "🎒 背包",
            time: "时间:",
            continueText: "继续",
            restart: "重新开始",
            nextChapter: "下一章",
            returnToChapterSelect: "返回章节选择",
            congratulations: "恭喜通关!",
            chapter: "章节:",
            clearTime: "通关时间:",
            youDied: "你遭遇了不幸...",
            inventoryEmpty: "物品栏为空",
            confirm: "确认",
            cancel: "取消",
            close: "关闭",
            ok: "确定",
            understand: "了解"
        },

        // 死亡消息
        deathMessages: {
            facelessGhost: "当你靠近她时，她缓缓转过头——那是一张没有脸的脸！你尖叫着倒下...",
            leglessFloat: "你转过身，看到一个没有腿的人漂浮在半空中，正伸出苍白的手抓向你...",
            mirrorSmile: "当你看向镜子时，镜中的你露出了诡异的笑容，然后慢慢爬出了镜子...",
            coldTouch: "你的手摸到了一个冰冷的东西，然后听到一个声音在你耳边说：\"你在找这个吗？\"",
            windowBars: "窗户被铁条封死了，当你靠近时，一只冰冷的手从铁条间伸了出来抓住了你！",
            deskCrush: "桌子开始剧烈摇晃，然后整个压了下来...",
            footstepsChase: "脚步声越来越近...你没能及时打开门，被黑暗中的东西抓住了！",
            bookshelfCrush: "你决定不拿钥匙，这时书架突然倒塌，把你压在了下面...",
            meltingFace: "站在你身后的是一个穿着校服的学生，他的脸正在慢慢融化...",
            blackMist: "门锁突然转动，但门打开的瞬间，一股黑色的雾气涌了进来，吞噬了你...",
            ghostAttack: "女孩的鬼魂扑向了你，你感到一阵刺骨的寒冷，然后什么都不知道了...",
            fireBurn: "火焰烧伤了你的手，你痛得尖叫起来。火势突然变大，将你吞噬...",
            lotusPoison: "莲花突然绽放，喷出黑色的毒液，将你腐蚀...",
            fruitExplosion: "果实突然炸开，释放出有毒的气体，你呼吸困难...",
            friendGrasp: "{friendName}的手紧紧抓住你，你感到一股寒意传遍全身。眼前一黑，你失去了意识...",
            darkRobeAttack: "黑袍人发出一声怒吼，黑雾瞬间将你吞噬。你感到一阵剧痛，然后什么都不知道了..."
        },

        // 章节标题和描述
        chapters: {
            prologue: {
                title: "序章-「晚自习后」",
                description: "在一个普通的晚自习后，你发现自己被困在了学校里..."
            },
            chapter1: {
                title: "第一章-「初见幽凄」",
                description: "探索学校的神秘事件，解开隐藏的秘密。完成序章后解锁。",
                unlockedDescription: "探索学校的神秘事件，解开隐藏的秘密。找到生锈的钥匙，面对镜中的幽魂，揭露校园背后的真相。"
            },
            chapter2: {
                title: "第二章-「宿舍鬼影」",
                description: "遇见第一位朋友，发现更多关于学校的秘密。完成第一章后解锁。",
                unlockedDescription: "遇见第一位朋友，发现更多关于学校的秘密。探索宿舍区，解开鬼影之谜。"
            },
            chapter3: {
                title: "第三章-「永夜沉沦」",
                description: "揭开学校的最终秘密，直面真相。完成第二章后解锁。",
                unlockedDescription: "揭开学校的最终秘密，直面真相。深入地下实验室，阻止黑暗仪式。"
            },
            chapter4: {
                title: "第四章-「轮回重启」",
                description: "逃离学校后，诅咒依然追随着你。完成第三章后解锁。",
                unlockedDescription: "逃离学校后，诅咒依然追随着你。寻找解除诅咒的方法，面对过去的阴影。"
            }
        },

        // 物品名称和描述
        items: {
            names: {
                "手机": "手机",
                "发银光的钥匙": "发银光的钥匙",
                "笔记本": "笔记本",
                "手电筒": "手电筒",
                "药草": "药草",
                "怕水纸条": "怕水纸条",
                "镜子倒影纸条": "镜子倒影纸条",
                "地下室地图": "地下室地图",
                "生锈的钥匙": "生锈的钥匙",
                "图书馆钥匙": "图书馆钥匙",
                "神秘钥匙": "神秘钥匙",
                "日记残页": "日记残页",
                "锤子": "锤子",
                "禁区地图": "禁区地图",
                "徽章": "徽章",
                "矿泉水": "矿泉水",
                "纱布": "纱布",
                "便签": "便签",
                "仪式匕首": "仪式匕首",
                "古老卷轴": "古老卷轴",
                "水之 artifact": "水之神器",
                "生命 artifact": "生命神器",
                "火焰 artifact": "火焰神器",
                "黑暗神器": "黑暗神器",
                "刻痕戒指": "刻痕戒指"
            },
            descriptions: {
                "手机": "你的智能手机，电量充足，可以用来照明和查看时间。",
                "发银光的钥匙": "一把发银光的钥匙，刻有\"校长办公室\"的字样。",
                "笔记本": "一本旧笔记本，上面记录着学生的日记和一些奇怪的符号。",
                "手电筒": "可以在黑暗中照明的工具，电池电量未知。",
                "药草": "一种神秘的药草，散发着淡淡的香气，可能有特殊功效。",
                "怕水纸条": "一张从教室找到的纸条，上面写着：\"它不喜欢噪音，用水可以暂时驱赶它\"。",
                "镜子倒影纸条": "一张从校长办公室抽屉找到的泛黄纸条，上面写着：\"不要相信镜子里的倒影\"。",
                "地下室地图": "一张手绘的地图，详细标记着学校地下结构和通往地下室的安全路径。",
                "生锈的钥匙": "一把生锈的铁钥匙，在第一章获得，可以用来驱散鬼怪和打开隐藏门。",
                "图书馆钥匙": "一把普通的钥匙，刻有\"图书馆\"的字样。",
                "神秘钥匙": "刻有神秘符号的铜钥匙，似乎与学校历史有关。",
                "日记残页": "残缺的学生日记，记录着10月13日的异常事件。",
                "锤子": "生锈的铁锤，握柄缠着破布，仍有使用痕迹。",
                "禁区地图": "标记着神秘区域的泛黄地图，带有神秘标注。",
                "徽章": "银质校徽，边缘刻着与钥匙相同的符号。",
                "矿泉水": "未开封的矿泉水，瓶身有便利店标签。",
                "纱布": "医用灭菌纱布，包装略有破损。",
                "便签": "一张写着神秘信息的便签纸。",
                "仪式匕首": "一把用于仪式的匕首，刀刃闪着寒光。",
                "古老卷轴": "记载着学校历史的古老卷轴，上面的文字已经有些模糊。",
                "水之 artifact": "蓝色的宝石，蕴含着水的力量，刻着神秘符号。",
                "生命 artifact": "绿色的宝石，蕴含着生命的力量，刻着神秘符号。",
                "火焰 artifact": "红色的宝石，蕴含着火焰的力量，刻着神秘符号。",
                "黑暗神器": "黑色的石头，散发着微弱的紫光，蕴含着危险的力量。",
                "刻痕戒指": "银质戒指，上面刻着和徽章相同的符号。"
            }
        },

        // 游戏描述文本
        gameDescription: {
            intro: "在一个普通的晚自习后，你发现自己被困在了学校里，随着夜幕降临，校园里开始发生诡异的事情...",
            subtitle: ""
        },

        // 关于页面文本
        about: {
            title: "🏆 关于本作品",
            content: [
                "本作品参加本次2025国庆Vibe创作大赛",
                "作者： 坦率的血翼蝠5801",
                "版本号： Version",
                "使用IDE： Trae CN",
                "调用AI模型：",
                "DeepSeekR1、Kimi-K2、",
                "Qwen-3-Coder、Doubao-Seed-1.6",
                "特别鸣谢： 神岛实验室"
            ]
        },

        // 音效提示文本
        audioNotice: {
            title: "⚠️ Version",
            warning: [
                "从 1.1.5.1 开始，我们加入了音效支持。",
                "本版本包含大量恐怖元素，可能含有部分使人感到不适的图像、音频、文本，",
                "如果感到生理不适，请立刻退出该游戏，否则@坦率的血翼蝠5801概不负责",
                "如果游戏中发现部分按钮点击无效，说明该按钮你尚未解锁，如果两个都点击无效，请尝试Ctrl+R或F5刷新网页(会保存你已解锁的关卡！)"
            ],
            iKnow: "我知道了"
        },

        // 地点名称
        locations: {
            classroom: "🏫 你的教室",
            corridor: "🚪 学校走廊",
            library: "📚 图书馆",
            bathroom: "🚻 卫生间",
            principalOffice: "🔑 校长办公室",
            staircase: "🔺 楼梯间",
            artRoom: "🎨 美术教室",
            basement: "🔻 地下室",
            deepCorridor: "🚶‍♂️ 昏暗走廊",
            exit: "🚪 侧门出口",
            undergroundPassage: "🔦 地下通道",
            ironDoorArea: "🔐 铁门区域",
            slimeExit: "💧 粘液出口",
            stoneDoorChamber: "🏛️ 石门密室",
            redPlayground: "🔴 红色操场",
            undergroundAbyss: "🕳️ 地下深渊",
            hiddenCatacombs: "⚰️ 隐藏墓穴",
            innerSanctum: "🔮 内殿",
            flowerField: "🌺 花海空间",
            upperFloor: "🔼 上层走廊",
            upperFloorCorridor: "🔄 楼上走廊",
            principalsOffice: "👨‍💼 校长办公室",
            creatureLair: "🐉 生物巢穴",
            lotusDimension: "🪷 莲花维度",
            entrance: "🚪 学校入口",
            quadrangle: "🏫 校园广场",
            dormitory: "🏠 宿舍区",
            canteen: "🍽️ 食堂",
            storageRoom: "🔒 仓库",
            schoolGate: "🚪 学校大门",
            foyer: "🏫 教学楼大厅",
            abandonedWing: "🏚️ 废弃教学楼",
            labyrinth: "🌀 地下迷宫",
            altarRoom: "🩸 祭坛房间",
            unknown: "未知地点"
        },

        // 错误信息
        errors: {
            chapterLocked: "你还没有解锁该关卡",
            customChapterNotAvailable: "该功能还在内测中，暂不可用",
            cannotLoadChapter: "无法加载章节内容，请确保对应文件已正确加载。"
        },

        // 章节对话
        dialogues: {
            // 序章对话
            prologue: {
                classroomStart: "晚自习结束的铃声已经响过很久了，{playerName}，你为什么还留在教室里？",
                leaveClassroom: "收拾书包回家",
                stayInClassroom: "再复习一会儿",
                doorLocked: "当你走到教室门口时，发现门锁住了！无论怎么推拉都打不开。",
                checkWindow: "检查窗户",
                searchForKey: "寻找钥匙",
                lightsOut: "时间一分一秒过去，突然，教室的灯全部熄灭了！",
                usePhoneLight: "拿出手机照明",
                hideUnderDesk: "躲到桌子底下",
                emptyClassroom: "教室里空荡荡的，只有你的课桌还留在原地。",
                leaveClassroomChoice: "离开教室",
                goToCorridor: "走向走廊",
                continueChoice: "继续",
                phoneLightRevealsNote: "手机屏幕亮起，你看到讲台上有一张纸条。",
                takeNote: "拿起纸条"
            },
            // 通用选择
            common: {
                continue: "继续",
                back: "返回",
                leave: "离开",
                investigate: "调查",
                yes: "是",
                no: "否",
                pickup: "拿起",
                examine: "查看",
                escape: "逃跑",
                attack: "攻击",
                defend: "防御",
                help: "帮助"
            }
        }
    },

    en: {
        // 通用界面文本
        ui: {
            gameTitle: "HorrorSchool",
            selectLanguage: "Choose Language / 选择语言 / 言語を選択",
            chinese: "中文",
            english: "English",
            japanese: "日本語",
            startGame: "Start Game",
            about: "About",
            returnToMain: "Return to Main",
            selectChapter: "Select Chapter",
            playerName: "Your Name:",
            nameplaceholder: "Enter your name...",
            selectGender: "Select Gender:",
            male: "Male",
            female: "Female",
            // 性别显示翻译
            genderDisplay: {
                male: "Male",
                female: "Female",
                "沃尔玛购物袋": "Walmart Shopping Bag",
                "武装直升机": "Attack Helicopter"
            },
            backpack: "🎒 Backpack",
            time: "Time:",
            continueText: "Continue",
            restart: "Restart",
            nextChapter: "Next Chapter",
            returnToChapterSelect: "Return to Chapter Select",
            congratulations: "Congratulations!",
            chapter: "Chapter:",
            clearTime: "Clear Time:",
            youDied: "You have met an unfortunate end...",
            inventoryEmpty: "Inventory is empty",
            confirm: "Confirm",
            cancel: "Cancel",
            close: "Close",
            ok: "OK",
            understand: "Understand"
        },

        // 死亡消息
        deathMessages: {
            facelessGhost: "As you approach her, she slowly turns around—revealing a face with no face! You scream and fall down...",
            leglessFloat: "You turn around to see a legless figure floating in mid-air, reaching out with pale hands to grab you...",
            mirrorSmile: "When you look in the mirror, your reflection shows a sinister smile, then slowly crawls out of the mirror...",
            coldTouch: "Your hand touches something ice-cold, then you hear a voice whisper in your ear: \"Are you looking for this?\"",
            windowBars: "The window is sealed with iron bars. As you approach, an icy hand reaches through the bars and grabs you!",
            deskCrush: "The desk starts shaking violently, then crashes down on you...",
            footstepsChase: "The footsteps are getting closer... You couldn't open the door in time and were caught by something in the darkness!",
            bookshelfCrush: "You decide not to take the key, then the bookshelf suddenly collapses and crushes you underneath...",
            meltingFace: "Standing behind you is a student in school uniform, whose face is slowly melting...",
            blackMist: "The lock suddenly turns, but the moment the door opens, a black mist rushes in and devours you...",
            ghostAttack: "The girl's ghost lunges at you. You feel a bone-chilling cold, then know nothing more...",
            fireBurn: "The flames burn your hand and you scream in pain. The fire suddenly grows larger and consumes you...",
            lotusPoison: "The lotus suddenly blooms and sprays black poison, corroding you...",
            fruitExplosion: "The fruit suddenly explodes, releasing toxic gas that makes you unable to breathe...",
            friendGrasp: "{friendName}'s hand grips you tightly. You feel a chill spread through your body. Your vision goes black and you lose consciousness...",
            darkRobeAttack: "The hooded figure lets out a roar of anger. Black mist instantly engulfs you. You feel intense pain, then know nothing more..."
        },

        // 章节标题和描述  
        chapters: {
            prologue: {
                title: "Prologue - \"After Evening Study\"",
                description: "After an ordinary evening study session, you find yourself trapped in the school..."
            },
            chapter1: {
                title: "Chapter 1 - \"First Encounter with Eeriness\"",
                description: "Explore mysterious events at school and uncover hidden secrets. Unlocked after completing prologue.",
                unlockedDescription: "Explore mysterious events at school and uncover hidden secrets. Find the rusty key, face the specter in the mirror, and reveal the truth behind the campus."
            },
            chapter2: {
                title: "Chapter 2 - \"Dormitory Shadows\"",
                description: "Meet your first friend and discover more secrets about the school. Unlocked after completing Chapter 1.",
                unlockedDescription: "Meet your first friend and discover more secrets about the school. Explore the dormitory area and solve the mystery of the shadows."
            },
            chapter3: {
                title: "Chapter 3 - \"Eternal Night Descent\"",
                description: "Uncover the school's final secret and face the truth. Unlocked after completing Chapter 2.",
                unlockedDescription: "Uncover the school's final secret and face the truth. Delve into the underground laboratory and stop the dark ritual."
            },
            chapter4: {
                title: "Chapter 4 - \"Cycle Restart\"",
                description: "After escaping the school, the curse still follows you. Unlocked after completing Chapter 3.",
                unlockedDescription: "After escaping the school, the curse still follows you. Find a way to break the curse and face the shadows of the past."
            }
        },

        // 物品名称和描述
        items: {
            names: {
                "手机": "Phone",
                "发银光的钥匙": "Silver Glowing Key",
                "笔记本": "Notebook",
                "手电筒": "Flashlight",
                "药草": "Herb",
                "怕水纸条": "Water-Fearing Note",
                "镜子倒影纸条": "Mirror Reflection Note",
                "地下室地图": "Basement Map",
                "生锈的钥匙": "Rusty Key",
                "图书馆钥匙": "Library Key",
                "神秘钥匙": "Mysterious Key",
                "日记残页": "Diary Fragment",
                "锤子": "Hammer",
                "禁区地图": "Forbidden Zone Map",
                "徽章": "Badge",
                "矿泉水": "Mineral Water",
                "纱布": "Bandage",
                "便签": "Note",
                "仪式匕首": "Ritual Dagger",
                "古老卷轴": "Ancient Scroll",
                "水之 artifact": "Water Artifact",
                "生命 artifact": "Life Artifact",
                "火焰 artifact": "Fire Artifact",
                "黑暗神器": "The Dark Artifact",
                "刻痕戒指": "Engraved Ring",
                "心理学导论": "Introduction to Psychology"
            },
            descriptions: {
                "手机": "Your smartphone with sufficient battery, can be used for lighting and checking time.",
                "发银光的钥匙": "A silver glowing key engraved with 'Principal's Office'.",
                "笔记本": "An old notebook recording student diaries and strange symbols.",
                "手电筒": "A tool for lighting in darkness, battery level unknown.",
                "药草": "A mysterious herb with a faint fragrance, may have special effects.",
                "怕水纸条": "A note found in the classroom that reads: 'It doesn't like noise, water can temporarily drive it away'.",
                "镜子倒影纸条": "A yellowed note found in the principal's office drawer that reads: 'Don't trust the reflection in the mirror'.",
                "地下室地图": "A hand-drawn map detailing the school's underground structure and safe paths to the basement.",
                "生锈的钥匙": "A rusty iron key obtained in Chapter 1, can be used to ward off ghosts and open hidden doors.",
                "图书馆钥匙": "An ordinary key engraved with 'Library'.",
                "神秘钥匙": "A bronze key with mysterious symbols, seems related to school history.",
                "日记残页": "Incomplete student diary recording abnormal events on October 13th.",
                "锤子": "A rusty iron hammer with cloth wrapped around the handle, still shows signs of use.",
                "禁区地图": "A yellowed map marking mysterious areas with cryptic annotations.",
                "徽章": "A silver school badge with the same symbols as the key engraved on the edge.",
                "矿泉水": "Unopened mineral water with a convenience store label.",
                "纱布": "Medical sterile gauze with slightly damaged packaging.",
                "便签": "A note with mysterious information written on it.",
                "仪式匕首": "A dagger used for rituals, the blade gleams coldly.",
                "古老卷轴": "An ancient scroll recording school history, the text is somewhat blurred.",
                "水之 artifact": "A blue gem containing the power of water, engraved with mysterious symbols.",
                "生命 artifact": "A green gem containing the power of life, engraved with mysterious symbols.",
                "火焰 artifact": "A red gem containing the power of fire, engraved with mysterious symbols.",
                "黑暗神器": "A black stone emitting faint purple light, containing dangerous power.",
                "刻痕戒指": "A silver ring engraved with the same symbols as the badge."
            }
        },

        // 游戏描述文本
        gameDescription: {
            intro: "After an ordinary evening study session, you find yourself trapped in the school, and as night falls, strange things begin to happen on campus...",
            subtitle: ""
        },

        // 关于页面文本
        about: {
            title: "🏆 About This Work",
            content: [
                "This work participates in the 2025 National Day Vibe Creation Contest",
                "Participant: Frankly Speaking Blood-winged Bat 5801",
                "Version: Version",
                "IDE Used: Trae CN",
                "AI Models Called:",
                "DeepSeekR1, Kimi-K2,",
                "Qwen-3-Coder, Doubao-Seed-1.6",
                "Special Thanks: Shendao Laboratory"
            ]
        },

        // 音效提示文本
        audioNotice: {
            title: "⚠️ Version",
            warning: [
                "Starting from version 1.1.5.1, we have added audio support.",
                "This version contains a large amount of horror elements, which may include some images, audio, and text that make people feel uncomfortable.",
                "If you feel physically uncomfortable, please exit the game immediately, otherwise @Frankly Speaking Blood-winged Bat 5801 is not responsible",
                "If you find that some buttons in the game are not responding, it means you haven't unlocked that button yet. If both are not responding, please try Ctrl+R or F5 to refresh the webpage (your unlocked levels will be saved!)"
            ],
            iKnow: "I Know"
        },

        // 地点名称
        locations: {
            classroom: "🏫 Your Classroom",
            corridor: "🚪 School Hallway",
            library: "📚 Library",
            bathroom: "🚻 Restroom",
            principalOffice: "🔑 Principal's Office",
            staircase: "🔺 Stairwell",
            artRoom: "🎨 Art Room",
            basement: "🔻 Basement",
            deepCorridor: "🚶‍♂️ Dark Corridor",
            exit: "🚪 Side Exit",
            undergroundPassage: "🔦 Underground Passage",
            ironDoorArea: "🔐 Iron Door Area",
            slimeExit: "💧 Slime Exit",
            stoneDoorChamber: "🏛️ Stone Door Chamber",
            redPlayground: "🔴 Red Playground",
            undergroundAbyss: "🕳️ Underground Abyss",
            hiddenCatacombs: "⚰️ Hidden Catacombs",
            innerSanctum: "🔮 Inner Sanctum",
            flowerField: "🌺 Flower Field",
            upperFloor: "🔼 Upper Floor",
            upperFloorCorridor: "🔄 Upper Corridor",
            principalsOffice: "👨‍💼 Principal's Office",
            creatureLair: "🐉 Creature's Lair",
            lotusDimension: "🪷 Lotus Dimension",
            entrance: "🚪 School Entrance",
            quadrangle: "🏫 Campus Quadrangle",
            dormitory: "🏠 Dormitory Area",
            canteen: "🍽️ Cafeteria",
            storageRoom: "🔒 Storage Room",
            schoolGate: "🚪 School Gate",
            foyer: "🏫 School Foyer",
            abandonedWing: "🏚️ Abandoned Wing",
            labyrinth: "🌀 Underground Labyrinth",
            altarRoom: "🩸 Altar Room",
            unknown: "Unknown Location"
        },

        // 错误信息
        errors: {
            chapterLocked: "You haven't unlocked this level yet",
            customChapterNotAvailable: "This feature is still in beta and not available",
            cannotLoadChapter: "Unable to load chapter content, please ensure the corresponding file is loaded correctly."
        },

        // 章节对话
        dialogues: {
            // 序章对话
            prologue: {
                classroomStart: "The evening study bell rang a long time ago, {playerName}, why are you still in the classroom?",
                leaveClassroom: "Pack up and go home",
                stayInClassroom: "Study a bit more",
                doorLocked: "When you walk to the classroom door, you find it's locked! No matter how hard you push or pull, it won't open.",
                checkWindow: "Check the window",
                searchForKey: "Search for a key",
                lightsOut: "Time passes by, suddenly, all the classroom lights go out!",
                usePhoneLight: "Use phone for light",
                hideUnderDesk: "Hide under the desk",
                emptyClassroom: "The classroom is empty, only your desk remains in place.",
                leaveClassroomChoice: "Leave classroom",
                goToCorridor: "Go to corridor",
                continueChoice: "Continue"
            },
            // 通用选择
            common: {
                continue: "Continue",
                back: "Back",
                leave: "Leave",
                investigate: "Investigate",
                yes: "Yes",
                no: "No",
                pickup: "Pick up",
                examine: "Examine",
                escape: "Escape",
                attack: "Attack",
                defend: "Defend",
                help: "Help"
            }
        }
    },

    ja: {
        // 通用界面文本
        ui: {
            gameTitle: "学園怪奇物語",
            selectLanguage: "言語を選択 / Choose Language / 选择语言",
            chinese: "中文",
            english: "English",
            japanese: "日本語",
            startGame: "ゲーム開始",
            about: "について",
            returnToMain: "メインに戻る",
            selectChapter: "チャプター選択",
            playerName: "あなたの名前:",
            nameplaceholder: "名前を入力...",
            selectGender: "性別を選択:",
            male: "男性",
            female: "女性",
            // 性别显示翻译
            genderDisplay: {
                male: "男性",
                female: "女性",
                "沃尔玛购物袋": "ウォルマートのショッピングバッグ",
                "武装直升机": "武装ヘリコプター"
            },
            backpack: "🎒 バックパック",
            time: "時間:",
            continueText: "続行",
            restart: "リスタート",
            nextChapter: "次のチャプター",
            returnToChapterSelect: "チャプター選択に戻る",
            congratulations: "おめでとうございます！",
            chapter: "チャプター:",
            clearTime: "クリア時間:",
            youDied: "不幸な結末を迎えました...",
            inventoryEmpty: "インベントリは空です",
            confirm: "確認",
            cancel: "キャンセル",
            close: "閉じる",
            ok: "OK",
            understand: "理解"
        },

        // 死亡消息
        deathMessages: {
            facelessGhost: "彼女に近づくと、ゆっくりと振り返る—それは顔のない顔だった！あなたは叫んで倒れ込む...",
            leglessFloat: "振り返ると、脚のない人影が宙に浮いて、青白い手を伸ばしてあなたを掴もうとしている...",
            mirrorSmile: "鏡を見ると、鏡の中のあなたが不気味な笑みを浮かべ、ゆっくりと鏡から這い出してくる...",
            coldTouch: "あなたの手が氷のように冷たいものに触れ、そして耳元で声が囁く：\"これを探しているの？\"",
            windowBars: "窓は鉄格子で封じられている。近づくと、格子の間から氷のような手が伸びてあなたを掴む！",
            deskCrush: "机が激しく震え始め、そして全体があなたの上に倒れ込んでくる...",
            footstepsChase: "足音がどんどん近づいてくる...ドアを開ける時間がなく、暗闇の中の何かに捕まってしまった！",
            bookshelfCrush: "鍵を取らないことにすると、本棚が突然倒れ、あなたを下敷きにする...",
            meltingFace: "あなたの後ろに立っているのは制服を着た学生で、その顔がゆっくりと溶けている...",
            blackMist: "錠が突然回り、ドアが開いた瞬間、黒い霧が流れ込んであなたを飲み込む...",
            ghostAttack: "少女の亡霊があなたに襲いかかる。骨を刺すような寒さを感じ、そして何も分からなくなった...",
            fireBurn: "炎があなたの手を焼き、痛みで叫び声をあげる。火勢が突然大きくなり、あなたを飲み込む...",
            lotusPoison: "蓮の花が突然咲き、黒い毒液を噴射してあなたを腐食させる...",
            fruitExplosion: "果実が突然爆発し、有毒ガスを放出して呼吸困難にさせる...",
            friendGrasp: "{friendName}の手があなたをしっかりと掴む。全身に寒気が広がるのを感じ、目の前が真っ暗になって意識を失う...",
            darkRobeAttack: "黒いローブの人物が怒りの咆哮を上げ、黒い霧が瞬時にあなたを飲み込む。激しい痛みを感じ、そして何も分からなくなった..."
        },

        // 章節標題和描述
        chapters: {
            prologue: {
                title: "プロローグ -「夜間自習の後」",
                description: "普通の夜間自習の後、あなたは学校に閉じ込められていることに気づいた..."
            },
            chapter1: {
                title: "第1章 -「初めての不気味な出会い」",
                description: "学校の神秘的な事件を探索し、隠された秘密を明かす。プロローグクリア後にアンロック。",
                unlockedDescription: "学校の神秘的な事件を探索し、隠された秘密を明かす。錆びた鍵を見つけ、鏡の中の亡霊と対峙し、キャンパスの真実を暴露する。"
            },
            chapter2: {
                title: "第2章 -「寮の影」",
                description: "最初の友達に出会い、学校についてさらなる秘密を発見する。第1章クリア後にアンロック。",
                unlockedDescription: "最初の友達に出会い、学校についてさらなる秘密を発見する。寮エリアを探索し、影の謎を解く。"
            },
            chapter3: {
                title: "第3章 -「永遠の夜の降下」",
                description: "学校の最終的な秘密を明かし、真実と向き合う。第2章クリア後にアンロック。",
                unlockedDescription: "学校の最終的な秘密を明かし、真実と向き合う。地下実験室に深く入り、暗黒の儀式を阻止する。"
            },
            chapter4: {
                title: "第4章 -「サイクルリスタート」",
                description: "学校から脱出した後も、呪いはあなたを追い続ける。第3章クリア後にアンロック。",
                unlockedDescription: "学校から脱出した後も、呪いはあなたを追い続ける。呪いを解く方法を見つけ、過去の影と向き合う。"
            }
        },

        // 物品名称和描述
        items: {
            names: {
                "手机": "携帯電話",
                "发银光的钥匙": "銀光の鍵",
                "笔记本": "ノート",
                "手电筒": "懐中電灯",
                "药草": "薬草",
                "怕水纸条": "水を恐れるメモ",
                "镜子倒影纸条": "鏡の反射メモ",
                "地下室地图": "地下室の地図",
                "生锈的钥匙": "錆びた鍵",
                "图书馆钥匙": "図書館の鍵",
                "神秘钥匙": "神秘の鍵",
                "日记残页": "日記の断片",
                "锤子": "ハンマー",
                "禁区地图": "禁止区域の地図",
                "徽章": "バッジ",
                "矿泉水": "ミネラルウォーター",
                "纱布": "包帯",
                "便签": "メモ",
                "仪式匕首": "儀式の短剣",
                "古老卷轴": "古い巻物",
                "水之 artifact": "水のアーティファクト",
                "生命 artifact": "生命のアーティファクト",
                "火焰 artifact": "炎のアーティファクト",
                "黑暗神器": "暗黒の神器",
                "刻痕戒指": "刻印のリング",
                "心理学导论": "心理学入門"
            },
            descriptions: {
                "手机": "十分な電池を持つスマートフォン、照明と時間確認に使用できます。",
                "发银光的钥匙": "「校長室」と刻まれた銀光の鍵。",
                "笔记本": "学生の日記と奇妙な記号が記録された古いノート。",
                "手电筒": "暗闇で照明するための道具、電池レベル不明。",
                "药草": "淡い香りを放つ神秘的な薬草、特別な効果があるかもしれません。",
                "怕水纸条": "教室で見つけたメモで、「それは騒音を嫌い、水で一時的に追い払える」と書かれている。",
                "镜子倒影纸条": "校長室の引き出しで見つけた黄ばんだメモで、「鏡の中の反射を信じるな」と書かれている。",
                "地下室地图": "学校の地下構造と地下室への安全なルートを詳細に記した手描きの地図。",
                "生锈的钥匙": "第1章で入手した錆びた鉄の鍵、幽霊を追い払い、隠されたドアを開くのに使える。",
                "图书馆钥匙": "「図書館」と刻まれた普通の鍵。",
                "神秘钥匙": "神秘的な記号が刻まれた青銅の鍵、学校の歴史と関係があるようです。",
                "日记残页": "10月13日の異常な事件を記録した不完全な学生の日記。",
                "锤子": "柄に布が巻かれた錆びた鉄のハンマー、まだ使用の痕跡がある。",
                "禁区地图": "神秘的な地域をマークした黄ばんだ地図、謎めいた注釈付き。",
                "徽章": "鍵と同じ記号が縁に刻まれた銀の校章。",
                "矿泉水": "コンビニエンスストアのラベルが付いた未開封のミネラルウォーター。",
                "纱布": "包装がわずかに破損した医療用滅菌ガーゼ。",
                "便签": "神秘的な情報が書かれたメモ。",
                "仪式匕首": "儀式用の短剣、刃が冷たく光っている。",
                "古老卷轴": "学校の歴史を記録した古い巻物、文字がやや不鮮明。",
                "水之 artifact": "水の力を含む青い宝石、神秘的な記号が刻まれている。",
                "生命 artifact": "生命の力を含む緑の宝石、神秘的な記号が刻まれている。",
                "火焰 artifact": "炎の力を含む赤い宝石、神秘的な記号が刻まれている。",
                "黑暗神器": "微かな紫の光を放つ黒い石、危険な力を含んでいる。",
                "刻痕戒指": "バッジと同じ記号が刻まれた銀のリング。"
            }
        },

        // 游戏描述文本
        gameDescription: {
            intro: "普通の夜間自習の後、あなたは学校に閉じ込められていることに気づき、夜が深くなるにつれ、キャンパスで奇妙なことが起こり始める...",
            subtitle: ""
        },

        // 关于页面文本
        about: {
            title: "🏆 この作品について",
            content: [
                "この作品は2025年国慶節Vibe創作コンテストに参加しています",
                "参加者：坦率的血翼蝠5801",
                "バージョン：Version",
                "使用IDE：Trae CN",
                "呼び出しAIモデル：",
                "DeepSeekR1、Kimi-K2、",
                "Qwen-3-Coder、Doubao-Seed-1.6",
                "特別感謝：神島実験室"
            ]
        },

        // 音效提示文本
        audioNotice: {
            title: "⚠️ Version",
            warning: [
                "バージョン1.1.5.1から、オーディオサポートを追加しました。",
                "このバージョンには大量のホラー要素が含まれており、人を不快にさせる可能性のある画像、オーディオ、テキストが一部含まれている可能性があります。",
                "身体的不快感を感じた場合は、すぐにゲームを終了してください。そうでなければ@坦率的血翼蝠5801は責任を負いません",
                "ゲーム中に一部のボタンが反応しない場合は、そのボタンがまだアンロックされていないことを意味します。両方とも反応しない場合は、Ctrl+Rまたはf5でWebページを更新してみてください（アンロックしたレベルは保存されます！）"
            ],
            iKnow: "分かりました"
        },

        // 地点名称
        locations: {
            classroom: "🏫 あなたの教室",
            corridor: "🚪 学校の廊下",
            library: "📚 図書館",
            bathroom: "🚻 お手洗い",
            principalOffice: "🔑 校長室",
            staircase: "🔺 階段",
            artRoom: "🎨 美術室",
            basement: "🔻 地下室",
            deepCorridor: "🚶‍♂️ 薄暗い廊下",
            exit: "🚪 横の出口",
            undergroundPassage: "🔦 地下通路",
            ironDoorArea: "🔐 鉄扉エリア",
            slimeExit: "💧 スライム出口",
            stoneDoorChamber: "🏛️ 石扉の部屋",
            redPlayground: "🔴 赤い運動場",
            undergroundAbyss: "🕳️ 地下深淵",
            hiddenCatacombs: "⚰️ 隠されたカタコンベ",
            innerSanctum: "🔮 内陣",
            flowerField: "🌺 花畑空間",
            upperFloor: "🔼 上層階",
            upperFloorCorridor: "🔄 上階の廊下",
            principalsOffice: "👨‍💼 校長室",
            creatureLair: "🐉 クリーチャーの巣",
            lotusDimension: "🪷 蓮の次元",
            entrance: "🚪 学校入口",
            quadrangle: "🏫 キャンパス広場",
            dormitory: "🏠 寮エリア",
            canteen: "🍽️ 食堂",
            storageRoom: "🔒 倉庫",
            schoolGate: "🚪 学校の門",
            foyer: "🏫 校舎ホール",
            abandonedWing: "🏚️ 廃棄校舎",
            labyrinth: "🌀 地下迷宮",
            altarRoom: "🩸 祭壇の部屋",
            unknown: "未知の場所"
        },

        // 错误信息
        errors: {
            chapterLocked: "まだこのレベルをアンロックしていません",
            customChapterNotAvailable: "この機能はまだベータ版で利用できません",
            cannotLoadChapter: "チャプターコンテンツをロードできません。対応するファイルが正しくロードされているか確認してください。"
        },

        // 章节对话
        dialogues: {
            // 序章对话
            prologue: {
                classroomStart: "夜間自習のベルがずっと前に鳴ったのに、{playerName}、どうしてまだ教室にいるの？",
                leaveClassroom: "荷物をまとめて帰る",
                stayInClassroom: "もう少し勉強する",
                doorLocked: "教室のドアに近づくと、ロックされていることがわかった！どんなに押しても引いても開かない。",
                checkWindow: "窓を確認する",
                searchForKey: "鍵を探す",
                lightsOut: "時間が過ぎていく中、突然、教室の電気がすべて消えた！",
                usePhoneLight: "携帯の明かりを使う",
                hideUnderDesk: "机の下に隠れる",
                emptyClassroom: "教室は空っぽで、あなたの机だけがそこに残っている。",
                leaveClassroomChoice: "教室を出る",
                goToCorridor: "廊下に向かう",
                continueChoice: "続行"
            },
            // 通用选择
            common: {
                continue: "続行",
                back: "戻る",
                leave: "去る",
                investigate: "調査",
                yes: "はい",
                no: "いいえ",
                pickup: "拾う",
                examine: "調べる",
                escape: "逃げる",
                attack: "攻撃",
                defend: "防御",
                help: "助ける"
            }
        }
    }
};

// i18n工具类
class I18n {
    constructor() {
        this.currentLanguage = 'zh'; // 默认中文
        this.data = i18nData;
        this.init();
    }

    init() {
        // 从localStorage获取保存的语言设置
        const savedLanguage = localStorage.getItem('gameLanguage');
        if (savedLanguage && this.data[savedLanguage]) {
            this.currentLanguage = savedLanguage;
        }
    }

    // 设置语言
    setLanguage(lang) {
        if (this.data[lang]) {
            this.currentLanguage = lang;
            localStorage.setItem('gameLanguage', lang);
            this.updatePageTexts();
            return true;
        }
        return false;
    }

    // 获取翻译文本
    t(path, defaultValue = '') {
        const keys = path.split('.');
        let value = this.data[this.currentLanguage];

        for (const key of keys) {
            if (value && typeof value === 'object' && value.hasOwnProperty(key)) {
                value = value[key];
            } else {
                return defaultValue || path;
            }
        }

        return value || defaultValue || path;
    }

    // 获取物品名称
    getItemName(originalName) {
        return this.t(`items.names.${originalName}`, originalName);
    }

    // 获取物品描述
    getItemDescription(originalName) {
        return this.t(`items.descriptions.${originalName}`, '');
    }

    // 获取对话文本（支持参数替换）
    getDialogue(path, params = {}) {
        let text = this.t(`dialogues.${path}`, '');

        // 替换参数
        Object.keys(params).forEach(key => {
            const placeholder = `{${key}}`;
            text = text.replace(new RegExp(placeholder, 'g'), params[key]);
        });

        return text;
    }

    // 更新页面中的所有文本
    updatePageTexts() {
        // 更新标题
        const titleElement = document.querySelector('title');
        if (titleElement) {
            titleElement.textContent = this.t('ui.gameTitle');
        }

        // 更新游戏标题
        const gameTitleElement = document.getElementById('game-title');
        if (gameTitleElement) {
            gameTitleElement.textContent = this.t('ui.gameTitle');
        }

        // 更新语言选择界面
        const languageTitleElement = document.querySelector('.language-title');
        if (languageTitleElement) {
            languageTitleElement.textContent = this.t('ui.selectLanguage');
        }

        // 更新语言按钮
        const langZhBtn = document.getElementById('lang-zh');
        const langEnBtn = document.getElementById('lang-en');
        const langJaBtn = document.getElementById('lang-ja');

        if (langZhBtn) langZhBtn.textContent = this.t('ui.chinese');
        if (langEnBtn) langEnBtn.textContent = this.t('ui.english');
        if (langJaBtn) langJaBtn.textContent = this.t('ui.japanese');

        // 更新开始界面
        this.updateStartScreen();

        // 更新章节选择界面
        this.updateChapterScreen();

        // 更新游戏界面
        this.updateGameScreen();

        // 更新关于页面
        this.updateAboutModal();

        // 更新音效提示
        this.updateAudioNotice();

        // 更新性别显示
        this.updateGenderDisplay();
    }

    // 更新开始界面
    updateStartScreen() {
        const playerNameLabel = document.querySelector('.name-input label');
        if (playerNameLabel) {
            playerNameLabel.textContent = this.t('ui.playerName');
        }

        const playerNameInput = document.getElementById('player-name');
        if (playerNameInput) {
            playerNameInput.placeholder = this.t('ui.nameplaceholder');
        }

        const genderSelectionP = document.querySelector('.gender-selection p');
        if (genderSelectionP) {
            genderSelectionP.textContent = this.t('ui.selectGender');
        }

        const maleOption = document.getElementById('male-option');
        const femaleOption = document.getElementById('female-option');
        if (maleOption) maleOption.textContent = this.t('ui.male');
        if (femaleOption) femaleOption.textContent = this.t('ui.female');

        const startBtn = document.getElementById('start-game');
        if (startBtn) startBtn.textContent = this.t('ui.startGame');

        const aboutBtn = document.getElementById('about-btn');
        if (aboutBtn) aboutBtn.textContent = this.t('ui.about');

        // 更新游戏描述
        const descriptionPs = document.querySelectorAll('.game-description p');
        if (descriptionPs.length >= 2) {
            descriptionPs[0].textContent = this.t('gameDescription.intro');
            descriptionPs[1].style.display = 'none'; // 隐藏subtitle段落
        }
    }

    // 更新章节选择界面
    updateChapterScreen() {
        const chapterTitle = document.querySelector('#chapter-select-screen .pixel-title');
        if (chapterTitle) {
            chapterTitle.textContent = this.t('ui.selectChapter');
        }

        const backToMainBtn = document.getElementById('back-to-main');
        if (backToMainBtn) {
            backToMainBtn.textContent = this.t('ui.returnToMain');
        }

        // 更新章节项目
        const chapterItems = document.querySelectorAll('.chapter-item');
        const chapters = ['prologue', 'chapter1', 'chapter2', 'chapter3', 'chapter4'];

        chapterItems.forEach((item, index) => {
            const chapter = chapters[index];
            if (chapter) {
                const h2 = item.querySelector('h2');
                const p = item.querySelector('p');

                if (h2) {
                    let title = this.t(`chapters.${chapter}.title`);
                    if (item.classList.contains('locked')) {
                        title += `<span class="lock-icon">🔒</span>`;
                    }
                    h2.innerHTML = title;
                }

                if (p) {
                    // 检查是否有解锁后的描述，如果没有则使用默认描述
                    const unlockedDescPath = `chapters.${chapter}.unlockedDescription`;
                    const unlockedDesc = this.t(unlockedDescPath);
                    const hasUnlockedDesc = unlockedDesc !== unlockedDescPath; // 如果翻译存在，返回值不会等于路径

                    const description = item.classList.contains('available') && hasUnlockedDesc
                        ? unlockedDesc
                        : this.t(`chapters.${chapter}.description`);
                    p.textContent = description;
                }
            }
        });
    }

    // 更新游戏界面
    updateGameScreen() {
        const timeLabel = document.querySelector('#game-time');
        if (timeLabel) {
            const timeSpan = timeLabel.querySelector('span');
            const timeText = timeSpan ? timeSpan.textContent : '21:00';
            timeLabel.innerHTML = `${this.t('ui.time')} <span id="current-time">${timeText}</span>`;
        }

        const inventoryTitle = document.querySelector('.inventory-title');
        if (inventoryTitle) {
            inventoryTitle.textContent = this.t('ui.backpack');
        }

        // 更新结算界面
        const congratsTitle = document.querySelector('#result-screen .pixel-title');
        if (congratsTitle) {
            congratsTitle.textContent = this.t('ui.congratulations');
        }

        const nextChapterBtn = document.getElementById('next-chapter-btn');
        if (nextChapterBtn) {
            nextChapterBtn.textContent = this.t('ui.nextChapter');
        }

        const backToChapterSelectBtn = document.getElementById('back-to-chapter-select');
        if (backToChapterSelectBtn) {
            backToChapterSelectBtn.textContent = this.t('ui.returnToChapterSelect');
        }

        // 更新死亡界面
        const deathTitle = document.querySelector('.death-title');
        if (deathTitle) {
            deathTitle.textContent = this.t('ui.youDied');
        }

        const restartBtn = document.getElementById('restart-game');
        if (restartBtn) {
            restartBtn.textContent = this.t('ui.restart');
        }
    }

    // 更新关于页面
    updateAboutModal() {
        const aboutModalHeader = document.querySelector('#about-modal .modal-header h2');
        if (aboutModalHeader) {
            aboutModalHeader.textContent = this.t('about.title');
        }

        const aboutModalBody = document.querySelector('#about-modal .modal-body');
        if (aboutModalBody) {
            const content = this.t('about.content');
            let html = '';
            content.forEach(line => {
                if (line.includes('Version')) {
                    html += `<p>${line} <span id="version-number">重生版1.0.0.0</span></p>`;
                } else {
                    html += `<p>${line}</p>`;
                }
            });
            aboutModalBody.innerHTML = html;
        }
    }

    // 更新音效提示
    updateAudioNotice() {
        const audioNoticeVersion = document.getElementById('audio-notice-version');
        if (audioNoticeVersion) {
            audioNoticeVersion.textContent = `${this.t('audioNotice.title')} R2-1.0.1.1`;
        }

        const audioModalContent = document.querySelector('#audio-notice-modal .modal-content');
        if (audioModalContent) {
            const warning = this.t('audioNotice.warning');
            let html = `<h3 id="audio-notice-version">${this.t('audioNotice.title')} R2-1.0.1.1</h3>`;
            warning.forEach(line => {
                html += `<p>${line}</p>`;
            });
            html += `<button id="audio-notice-confirm" class="modal-btn">${this.t('audioNotice.iKnow')}</button>`;
            audioModalContent.innerHTML = html;

            // 重新绑定事件监听器
            const audioModal = document.getElementById('audio-notice-modal');
            const audioConfirmBtn = document.getElementById('audio-notice-confirm');
            if (audioConfirmBtn && audioModal) {
                // 移除可能存在的旧事件监听器，然后添加新的
                audioConfirmBtn.addEventListener('click', function () {
                    audioModal.classList.add('hidden');
                });

                // 确保点击弹窗外部关闭功能仍然有效
                audioModal.addEventListener('click', function (e) {
                    if (e.target === audioModal) {
                        audioModal.classList.add('hidden');
                    }
                });
            }
        }
    }

    // 获取当前语言
    getCurrentLanguage() {
        return this.currentLanguage;
    }

    // 获取所有支持的语言
    getSupportedLanguages() {
        return Object.keys(this.data);
    }

    // 更新性别显示
    updateGenderDisplay() {
        const playerGenderDisplay = document.getElementById('player-gender-display');
        if (playerGenderDisplay && window.gameSystem && window.gameSystem.gameState && window.gameSystem.gameState.playerGender) {
            const gender = window.gameSystem.gameState.playerGender;
            const genderTranslation = this.t('ui.genderDisplay');

            if (genderTranslation && genderTranslation[gender]) {
                playerGenderDisplay.textContent = genderTranslation[gender];
            }
        }
    }

    // 获取死亡消息
    getDeathMessage(key, params = {}) {
        const message = this.t(`deathMessages.${key}`);
        // 处理参数替换（如 {friendName}）
        let result = message;
        for (const [paramKey, paramValue] of Object.entries(params)) {
            result = result.replace(new RegExp(`{${paramKey}}`, 'g'), paramValue);
        }
        return result;
    }

    // 获取地点名称
    getLocationName(location) {
        return this.t(`locations.${location}`, this.t('locations.unknown'));
    }
}

// 创建全局i18n实例
window.i18n = new I18n();

// 导出供其他模块使用
if (typeof module !== 'undefined' && module.exports) {
    module.exports = I18n;
}
